/**
 * 
 */
package leetCode;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author zhongfang
 *
 */
public class RelativeRanks {
    public static String[] findRelativeRanks(int[] nums) {
    	TreeMap<Integer, Integer> ints=new TreeMap<>();
    	String[] medals={"Gold Medal", "Silver Medal", "Bronze Medal"};
        for(int i=0;i<nums.length;i++){
        	ints.put(nums[i], i);
        }
        String[] results=new String[nums.length];
        int j=1;
        while (!ints.isEmpty()) {
        	Map.Entry<Integer, Integer> entry=ints.pollLastEntry();
        	if(j<=3){
            	results[entry.getValue()]=medals[j-1];
        	}else {
            	results[entry.getValue()]=""+j;
			}
        	j++;
		}
        return results;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] nums={5,4,3,2,1};
		String[] strings=findRelativeRanks(nums);
		for (String string : strings) {
			System.out.println(string);
		}
		System.out.println();
	}

}
